#ifndef MUC3_CONST_H_INCLUDED
#define MUC3_CONST_H_INCLUDED
#include "stdio.h"

using namespace std;

class CTextBlock {

public:
    CTextBlock();
    CTextBlock(char test[]);
    virtual ~CTextBlock();
    size_t length() const;


    char& operator[](std::size_t position)  const  // operator[] for
    { return pText[position]; }                           // const objects


    char& operator[](std::size_t position)               // operator[] for
    {
    return
      const_cast<char&>(                         // cast away const on
                                                 // op[]'s return type;
        static_cast<const CTextBlock&>(*this)     // add const to *this's type;
          [position]                            // call const version of op[]
      );

    }                           // non-const objects


//    char& operator[](std::size_t position) const   // inappropriate (but bitwise
//    { return pText[position]; }                    // const) declaration of
                                                 // operator[]

private:

    char *pText;
    mutable   size_t textLength;            // last calculated length of textblock
   mutable  bool lengthIsValid;                // whether length is currently valid

};


#endif // MUC3_CONST_H_INCLUDED
